package jobManagement.impl;

import java.rmi.RemoteException;

import org.globus.wsrf.ResourceContext;
import grid.stefan.namespaces.jobManagement.JobManagementService.StartJobManagerResponse;
import grid.stefan.namespaces.jobManagement.JobManagementService.StartJobManagerTimedResponse;
import grid.stefan.namespaces.jobManagement.JobManagementService.StopJobManagerResponse;
import grid.stefan.namespaces.jobManagement.JobManagementService.StartJobManager;
import grid.stefan.namespaces.jobManagement.JobManagementService.StartJobManagerTimed;
import grid.stefan.namespaces.jobManagement.JobManagementService.StopJobManager;
import grid.stefan.namespaces.jobManagement.JobManagementService.GetJobStatus;
import grid.stefan.namespaces.jobManagement.JobManagementService.GetJobManagerStatus;


public class JobManagementService {

	/*
	 * Private method that gets a reference to the resource specified in the
	 * endpoint reference.
	 */ 
	 
	private JobManagementResource getResource() throws RemoteException {
		Object resource = null;
		try {
			resource = ResourceContext.getResourceContext().getResource();
		} catch (Exception e) {
			throw new RemoteException("", e);
		}

		JobManagementResource jobManagementResource = (JobManagementResource) resource;
		return jobManagementResource;
	}

	/* Implementation of add, subtract, and getValue operations */

	public StartJobManagerResponse startJobManager(StartJobManager start) throws RemoteException {
		JobManagementResource jobManagementResource = getResource();
		jobManagementResource.startJobManager(start.getProxy(),start.getJobDescription());
		return new StartJobManagerResponse();
	}
	
	public StartJobManagerTimedResponse startJobManagerTimed(StartJobManagerTimed start) throws RemoteException {
		JobManagementResource jobManagementResource = getResource();
		jobManagementResource.startJobManagerTimed(start.getProxy(),start.getJobDescription(),start.getCounter());
		return new StartJobManagerTimedResponse();
	}

	public StopJobManagerResponse stopJobManager(StopJobManager stop) throws RemoteException {
		JobManagementResource jobManagementResource = getResource();
		jobManagementResource.stopJobManager();
		return new StopJobManagerResponse();
	}
	
	public String  getJobStatus(GetJobStatus status) throws RemoteException{
		JobManagementResource jobManagementResource = getResource();
		return jobManagementResource.getJobStatus();
		
	}
	
	public int  getJobManagerStatus(GetJobManagerStatus status) throws RemoteException {
		JobManagementResource jobManagementResource = getResource();
		return  jobManagementResource.getJobManagerStatus();
	}
}